﻿/* 
 Copyright (C) 2011  Amblox Project

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using Amblox.Handlers;
using Amblox.Net;

namespace Amblox.Game
{
    public class HabboClient
    {
        public NetConnection Connection;
        public Handler Handler;

        public Habbo Habbo;
        public Messenger Messenger;

        public bool Destroyed
        {
            get
            {
                if (Connection == null && Handler == null)
                    return true;
                else
                    return false;
            }
        }

        public bool CheckConnection
        {
            get
            {
                bool Check = true;

                try
                {
                    Connection.SendData("");
                }
                catch
                {
                    Check = false;
                }

                if (!Check && !Destroyed)
                    Destroy();

                return Check;
            }
        }

        public HabboClient(NetConnection Connection)
        {
            this.Connection = Connection;
            this.Handler = new Handler(this);
        }

        public void Destroy()
        {
            if (Destroyed)
                return;

            if (Connection != null && !Connection.Destroyed)
                Connection.Destroy();

            if(Handler != null && !Handler.Destroyed)
                Handler.Destroy();

            if (Habbo != null)
                Habbo.OnClientDestroyed();
        }
    }
}
